<?php

namespace app\admin\model;

use think\Model;


class PurchaseOrder extends Model
{

    

    

    // 表名
    protected $name = 'purchase_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'pay_type_text',
        'contract_id',
    ];

    public function contract()
    {
        return $this->belongsTo('Contract', 'contract_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    

    
    public function getPayTypeList()
    {
        return ['transfer' => __('Transfer'), 'cash' => __('Cash'), 'honour' => __('Honour'), 'check' => __('Check'), 'thirty' => __('Thirty'), 'sixty' => __('Sixty'), 'ninety' => __('Ninety'), 'overninety' => __('Overninety')];
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
